<%@page import="com.framework.entity.Global"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>统一任务管理</title>
<meta name="description" content="这是一个 首页面">
<meta name="keywords" content="index">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<meta name="apple-mobile-web-app-title" content="Amaze UI" />
<style>
.admin-main {
	background: #fff;
}

.table-bordered {
	border: none
}

.wddd-list-jtzl {
	padding: 10px 0 0 !important;
	text-align: center;
}

.wddd-list-jtzl>ul>li {
	float: left;
	cursor: pointer;
}

.dt-grid-extra-columns p {
	display: none !important;
}

.sqshplusC {
	height: 80px;
	margin-bottom: 5px;
	width: 80px;
}

.djzjsxtc select {
	width: 100%;
	border-radius: 4px;
	border: 1px solid #999;
	padding: 5px;
}

.gddiv {
	display: inline-block;
	padding: 4px 9px;
	border-radius: 5px;
}

.xlselect {
	display: none;
	padding: 0;
	border: 1px solid #f00;
	border-radius: 2px;
	position: absolute;
	text-align: center;
	left: 30px;
	top: -5px;
	width: 200px;
	color: #fff;
	background: #fff;
	z-index: 10000000;
}

.xlselect ul li {
	float: left;
	padding: 4px 5px 0;
}

.xlselect ul li:hover {
	background: #ccc;
}

.dybiaoti {
	font-size: 14px;
	line-height: 18px;
	color: #9567ff;
	margin-bottom: 5px;
	text-align: left;
}

.extra-column.visible-lg.visible-md.visible-sm.visible-xs {
	display: none !important;
}

.extra-column.extra-column-event.visible-lg.visible-md.visible-sm.visible-xs
	{
	display: none !important;
}
</style>

<jsp:include page="../../inc.jsp"></jsp:include>

</head>
<body>
	<!-- content start -->
	<div class="admin-content" style="min-height:316px;">

		<div class="am-cf am-padding">
			<div class="am-fl am-cf">
				<strong class="am-text-primary am-text-lg">${param.pagename}</strong>
			</div>
		</div>

		<!-- 条件检索开始 -->
		<div class="am-g"
			style="background:#fff;padding:15px 0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;"
			data-am-sticky="{top:51,animation: 'slide-top'}">
			<div class="am-u-sm-12 am-u-md-12 am-u-lg-12">

				<div class="am-btn-toolbar">
					<form id="form-search"  class="am-form">
						<div class="am-u-sm-12">
							<div class="am-form-group am-u-sm-6">
  								 <label for="doc-ds-ipt-3" class="am-u-sm-3 am-form-label">任务名称</label>
  								 <div class="am-u-sm-9">
  									<input id="doc-ds-ipt-3" type="text" name="job_name" class="am-form-field">
  								</div>
							</div>
						</div>
						<div class="am-u-sm-12">
							<div class="am-form-group am-u-sm-5">
						      <label for="doc-select-1" class="am-u-sm-3 am-form-label">任务组名</label>
						      <div class="am-u-sm-9">
							      <select id="doc-select-1" class="am-input-lg" name="job_group" >
							        <option value="-1">请选择</option>
							      </select>
						      </div>
						    </div>
						    <div class="am-form-group am-u-sm-5">
						      <label for="doc-select-2" class="am-u-sm-3 am-form-label">开启状态</label>
						      <div class="am-u-sm-9">
						      <select id="doc-select-2" class="am-input-lg" name="status" >
						        <option value="0">开启</option>
						        <option value="1">关闭</option>
						      </select>
						      </div>
						    </div>
							<div class="am-u-sm-2">
								<button class="am-btn am-btn-sm am-btn-primary am-radius "
								type="button" onClick="query();" style="padding:5px 8px;margin-left:10px">
								<li class="fa fa-search"></li>&nbsp;&nbsp;查找
								</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
		<div class="am-u-sm-12 am-pad-none">
			<div class="am-u-sm-12 am-u-md-12 am-u-lg-12 tablemenu">
				<div id="dtGridContainer_2_1_2" class="dt-grid-container"></div>
				<div id="dtGridToolBarContainer_2_1_2" class="dt-grid-toolbar-container"></div>
			</div>
		</div>
	</div>
	<div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-1" style="top:42%">
        <div class="admin-content">
            <div class="am-cf am-padding">
              <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">编辑</strong></div>
            </div>
          <form id="form" name="form">
          <input type="hidden" id="quartzId">
            <div class="am-tabs am-margin">
                  <div class="am-u-sm-12 djzjsxtc">
                      <div class="am-u-sm-4 am-text-center">
                      	任务名：
                      </div>
                      <div class="am-u-sm-8">
                          <input readonly="value" type="text" id ="jobName_edit" name = "pmgq.jobName">
                      </div>
                  </div>
                  <div class="am-u-sm-12 djzjsxtc">
                       <div class="am-u-sm-4 am-text-center">
                      	任务组名：
                      </div>
                      <div class="am-u-sm-8">
                     	 <select style="width: 100%; border-radius: 4px;border: 1px solid #999; padding: 5px;"  id="jobGroup_edit" >
                     	 	<option>无</option>
						 </select>
                      </div>
                  </div>
                  <div class="am-u-sm-12 djzjsxtc">
                      <div class="am-u-sm-4 am-text-center">
                  	      描述：
                      </div>
                      <div class="am-u-sm-8">
                          <input readonly="value" type="text" id = "description_edit" name = "pmgq.description">
                      </div>
                   </div>
                   <div class="am-u-sm-12 djzjsxtc">
                      <div class="am-u-sm-4 am-text-center">
                      	cronExpression：
                      </div>
                      <div class="am-u-sm-8">
                          <input readonly="value" type="text" id = "cronExpression" name = "pmgq.cronExpression">
                      </div>
                  </div>
                   <div class="am-u-sm-12 djzjsxtc">
                      <div class="am-u-sm-4 am-text-center">
                      	url路径：
                      </div>
                      <div class="am-u-sm-8">
                          <input readonly="value" type="text" id = "remoteUrl" name = "pmgq.remoteUrl">
                      </div>
                  </div>
                <div class="clear"></div>
            </div>
          </form>
            <div class="am-margin am-text-right">
              <button id="btn_sub" type="button" class="am-btn am-btn-primary am-btn-xs"  >提交保存</button>
              <button type="button" class="am-btn am-btn-primary am-btn-xs" data-am-modal-close>放弃保存</button>
            </div>
        </div>
    </div>

	<script type="text/javascript">
	$(function(){
		//查询任务组名
		getAllJobGroup();
	});
	
	function getAllJobGroup(){
		var url="${pageContext.request.contextPath}/jobManage/getAllJobGroup.action";
		$.get(url,function(data){
			$.each(data,function(i){
				$("#doc-select-1").append("<option value=\""+this+"\">"+this+"</option>");
			});
		});
	}
	
	function changeSelect1(v){
		$("#job_group").val(v);
	}
	function changeSelect2(v){
		$("#status").val(v);
	}
	</script>
	<script>
		var dtGridColumns_2_1_2 = [
		{id:'quartzId', title:'任务ID', type:'string',columnClass:'text-center'},
		{id:'jobName', title:'任务名', type:'string',columnClass:'text-center',resolution:function(value,record){
			return value;
		}},
		{id:'jobGroup', title:'任务组', type:'string',columnClass:'text-center',resolution:function(value,record){
			return value;
		}},
		{id:'description', title:'描述', type:'string',columnClass:'text-center',resolution:function(value,record){
			return value;
		}},
		{id:'cronExpression', title:'cronExpression', type:'string',columnClass:'text-center',resolution:function(value,record){
			return value;
		}},
		{id:'status', title:'状态', type:'string',columnClass:'text-center',resolution:function(value,record){
			return value==4?"<a onClick=\"changeStatus(0,'"+record.quartzId+"');\">开启</a>":"<a onClick=\"changeStatus(4,'"+record.quartzId+"');\">停止</a>";
		}},
		{id:'remoteUrl', title:'url路径', type:'string',columnClass:'text-center',resolution:function(value,record){
			return value;
		}},
		{id:'quartzId', title:'操作', type:'string',columnClass:'text-center',resolution:function(value,record){
				var html='';
				html+='<a href="javascript:void(0)" >立即执行</a>&nbsp;&nbsp;';
				html+='<a href="javascript:void(0)" onClick="toEdit('+record.quartzId+');">编辑</a>&nbsp;&nbsp;';
				html+='<a href="javascript:void(0)" onClick="toDel('+record.quartzId+');">删除</a>&nbsp;&nbsp;';
				
				return html;
		}}
		];

	var dtGridOption_2_1_2 = {
		lang : 'zh-cn',
		ajaxLoad : true,
		loadURL : '${pageContext.request.contextPath}/jobManage/showJobManageGrid.action',
		exportFileName : '任务调度器维护列表',
		columns : dtGridColumns_2_1_2,
		gridContainer : 'dtGridContainer_2_1_2',
		toolbarContainer : 'dtGridToolBarContainer_2_1_2',
		tools : '',
		pageSize : 10,
		pageSizeLimit : [10, 20, 50]
	};

	var grid_2_1_2 = $.fn.DtGrid.init(dtGridOption_2_1_2);
	$(function(){
		grid_2_1_2.load();
		//如果第一页数据较多请在load()之后直接reload(),以便出现进度条
		grid_2_1_2.reload();
	});

	
	//条件查询
	function query()
	{	//传入实例化好的dt-grid 如grid_2_1_9和条件筛选的form的id
		//如果有其他固定的筛选条件，请在条件筛选的form中放入隐藏域
		dtGridLoad(grid_2_1_2, "form-search");
	}

	//导出
	function order_excel_deshop(){
		var params = {};
		$("#form-search input").each(function(){
     		var parametersName = $(this).attr("name");
     		var parametersValue = $(this).val();
     		params[parametersName] = parametersValue;
     	});

     	var str =JSON.stringify(params);

		window.location.href="${pageContext.request.contextPath}/loginStatistics/exportExcel_html.action?parameters="+str;
	}

    function fadein(obj){
		$(obj).children("div").fadeIn();
	}
	function fadeout(obj){
		$(obj).children("div").fadeOut();
	}
	
	function changeStatus(s,quartzId){
		var url="${pageContext.request.contextPath}/jobManage/changeStatus.action?status="+s+"&&id="+quartzId;
		$.get(url,function(data){
			if(data)
				grid_2_1_2.load();
			else
				alert("状态变更失败，请稍后重试或联系管理员！");
		});
	}
	
	function toDel(quartzId){
		var url="${pageContext.request.contextPath}/jobManage/delQuartzSchedule.action?id="+quartzId;
		$.get(url,function(data){
			if(data)
				grid_2_1_2.load();
			else
				alert("任务删除失败，请稍后重试或联系管理员！");
		});
	}
	
	function toEdit(){
		var url="${pageContext.request.contextPath}/jobManage/toEdit.action?id="+quartzId;
		$.get(url,function(data){
			if(data!=null){
			var obj = eval("(" + data + ")");
			
			$("#doc-modal-1").modal('open');
			}else{
				alert("查询任务详情失败，请稍后重试或联系管理员！");
			}
		});
	}
	</script>
</body>

</html>
